package org.swingDemo;

import javax.swing.*;
import javax.swing.plaf.LayerUI;
import java.awt.*;

class WallpaperLayerUI extends LayerUI<JComponent> {
    @Override
    public void paint(Graphics g, JComponent c) {
        super.paint(g, c);

        Graphics2D g2d = (Graphics2D)g.create();

        int w = c.getWidth();
        int h = c.getHeight();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        g2d.setPaint(new GradientPaint(0, 0, Color.YELLOW, 0, h, Color.red));
        g2d.fillRect(0, 0, w, h);

        g2d.dispose();
    }
}

public class Wallpaper {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            createUI();
        });
    }

    public static void createUI() {
        JFrame f = new JFrame("Wallpaper");

        JPanel panel = createPanel();
        LayerUI<JComponent> layerUI = new WallpaperLayerUI();
        JLayer<JComponent> jLayer = new JLayer<JComponent>(panel, layerUI);

        f.add(jLayer);

        f.setSize(300, 200);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    private static JPanel createPanel() {
        JPanel p = new JPanel();

        ButtonGroup entreeGroup = new ButtonGroup();
        JRadioButton radioButton;
        p.add(radioButton = new JRadioButton("Beef", true));
        entreeGroup.add(radioButton);
        p.add(radioButton = new JRadioButton("Chicken"));
        entreeGroup.add(radioButton);
        p.add(radioButton = new JRadioButton("Vegetable"));
        entreeGroup.add(radioButton);

        p.add(new JCheckBox("Ketchup"));
        p.add(new JCheckBox("Mustard"));
        p.add(new JCheckBox("Pickless"));

        p.add(new JLabel("Special requests:"));
        p.add(new JTextField(20));

        JButton orderButton = new JButton("Place Order");
        p.add(orderButton);

        return p;
    }
}
